package com.blog.dao.impl;

import com.blog.dao.UserDao;
import com.blog.dao.base.impl.DaoImpl;
import com.blog.entity.User;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * Author:  Wu Yujie
 * Email:  coffee377@dingtalk.com
 * Time:  2017/02/16 00:32
 */
@Repository
public class UserDaoImpl extends DaoImpl<User> implements UserDao {
    @Override
    public boolean existUser(String userName) {
        return find("from User u where u.userName = ?", userName).size() > 0;
    }

    @Override
    public User login(String userName, String password) {
        List<User> user = this.find("from User u where u.userName = ? and u.password = ?", userName, password);
        if (user.size() > 0) {
            return user.get(0);
        }
        return null;
    }
}
